Skip to content

Fix the relative path reference resolution #1131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 20, 2014

Conversation

sheetalkamat
Copy link
Member

Compiler internally doesn't resolve the file paths to full disk paths unless necessary that results in reference resolution error when reading files that reference each other but aren't in same directory.
Eg.
src\ts\Manager\FieldManager.ts -- references ......\typings\tsd.ts
typings\tsd.ts -- reference ..\src\ts\Manager\FieldManager.ts

compiling FieldManager.ts from src\ts\Manager folder results in following reads
FieldManager.ts
......\typings\tsd.ts - as it is reference from fieldManager.ts
src\ts\Manager\FieldManager.ts as a normalized reference from tsd.ts but compiler doesn't know that this is same file as earlier read FieldManager.ts and ends up adding the text again and hence duplicate symbol errors

Fixed this by adding keeping track of disk resolved path -> SourceFile cache as well apart from just filename -> SourceFile cache when adding sourceFile to cache so if we try to lookup the same file with different relative path name, so we wouldn't end up creating multiple source files for references to the same file through different relative paths

Fixes #1039

export function tryResolveScriptReference(program: Program, sourceFile: SourceFile, reference: FileReference) {
var referenceFileName = isRootedDiskPath(reference.filename) ? reference.filename : combinePaths(getDirectoryPath(sourceFile.filename), reference.filename);
referenceFileName = normalizePath(referenceFileName);
if (!program.getCompilerOptions().noResolve) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand why noResolve is of any consequence here. we will come here because we decided to resolve references, correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we just need to compute an absolute path for every file for comparison purposes regardless of --noresolve, just do not make it the main name of the file so that error messages still use the name the user inputed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhegazy don't we say if --noResolve is given do not resolve file names on the disk but use whatever is given in to the compiler, so why should we be resolving to full name in case of --noResolve

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--noResolve=true means do not resolve /// references. the path resolution is more of a compiler implementation detail.

@Maks3w
Copy link

Maks3w commented Nov 19, 2014

I'm pleasure of use the same example I exposed in the issue but may is better use "standard" file and class names like Foo, Baz rather than FieldManager ;-)

--noResolve is only for ///reference and import file resolution to resolve files from disk
but the file identity is always determined before creating duplicate source file for same file paths
sheetalkamat added a commit that referenced this pull request Nov 20, 2014
@sheetalkamat sheetalkamat merged commit ff23748 into master Nov 20, 2014
@sheetalkamat sheetalkamat deleted the relativePathReferenceResolution branch November 20, 2014 23:59
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[error TS2300: Duplicate identifier] Global references
3 participants